<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 对象定义
        const obj = {
            name: '张三',
            age: 18,
        };

        // 对象取值
        console.log(obj.name); // 点语法
        console.log(obj['name']); // 方括号语法
        let key = 'name'
        console.log(obj[key]); // 方括号语法, 此时只能使用方括号语法


        
        // 简写
        let name = '张三';
        let age = 18;
        const obj2 = {
            name,
            age,
        };
        console.log(obj2);

        // 对象方法
        const obj3 = {
            name: '张三',
            age: 18,
            // 不简写
            fn: function say() {
                console.log('hello');
            },
            // 简写
            say() {
                console.log('hello');
            }
        };
    </script>
</body>

</html>